package Judge;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

import androidx.appcompat.app.AppCompatActivity;

import com.example.sports_meet.R;

import dateBase.Judge_Site_DBHelper;
import util.ToastUtil;

public class Judge_add extends AppCompatActivity implements View.OnClickListener {
    private EditText editName, editSex, editAge, editProject, editId;//数据库没记录电话
    private Button btnSub;
    private Judge_Site_DBHelper mHelper;
    private Spinner spinner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_judge_add);
        viewInit();

    }

    @Override
    protected void onStart() {
        super.onStart();
        mHelper = Judge_Site_DBHelper.getInstance(this);
        //打开读写链接
        mHelper.openReadLink();
        mHelper.openWriteLink();
        //获得帮助器实例
    }

    @Override
    protected void onStop() {
        super.onStop();
        mHelper.closeLink();
    }

    public void viewInit() {
        editName = (EditText) findViewById(R.id.editname);
        editSex = (EditText) findViewById(R.id.editsex);
        editAge = (EditText) findViewById(R.id.editage);
//        editPhone=(EditText) findViewById(R.id.editTextPhone);
        editProject = (EditText) findViewById(R.id.editproject);
        editId = (EditText) findViewById(R.id.editid);
        findViewById(R.id.btnsub).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnsub:
                String name = editName.getText().toString();
                String sex = editSex.getText().toString();
                String age = editAge.getText().toString();
                String project = editProject.getText().toString();
                String id = editId.getText().toString();
                JudgeBean judge = new JudgeBean(id, age, sex, project, name);
                long result = mHelper.insert(judge);
                if (result > 0) {
                    ToastUtil.show(this, "添加成功");
                } else if (result == -1) {
                    ToastUtil.show(this, "添加失败");
                }

                break;
        }

    }

    public void spinnerinit() {
        spinner = (Spinner) findViewById(R.id.spinner2);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.judge, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);

    }

}
